//
//  BaseViewController.m
//  jiajiao
//
//  Created by apple on 16/3/11.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "BaseViewController.h"
#import "specialButten.h"
#import "TitleBtn.h"
@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets =NO;
    self.view.backgroundColor = kbgColor;
//
    [self.navigationController.navigationBar setTranslucent:NO];

    
    int index = (int)[[self.navigationController viewControllers]indexOfObject:self];
    
    if (index==0) {
    }else
    {
        [self popVc];

    }
    // Do any additional setup after loading the view.
    
    //设置导航栏文字颜色及大小
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:kNavTitleColor}];
    
    //设置状态栏字体颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)setNavTitle:(NSString *)title
{
    self.navigationItem.title = title;
}
-(void)addtarget:(id)target with:(NSArray *)array

{
    NSMutableArray *mutablearray = [NSMutableArray array];
    
    for (NSInteger i=0; i<array.count; i++) {
        UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
        [butten setImage:[UIImage imageNamed:array[i][0]] forState:UIControlStateNormal];
        [butten addTarget:target action:NSSelectorFromString(array[i][1]) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *barbtnitem  = [[UIBarButtonItem alloc]initWithCustomView:butten];
        [mutablearray addObject:barbtnitem];

    }
    
    
    self.navigationItem.rightBarButtonItems =mutablearray;


}
//设置单个
-(void)addtarget:(id)target OneBtn:(UIImage *)image with:(SEL)clic;
{
    UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [butten setImage:image forState:UIControlStateNormal];
    butten.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [butten addTarget:target action:clic forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
}

-(void)addtarget:(id)target OneBtn:(UIImage *)image with:(SEL)clic withmessagecount:(NSInteger)count;
{
    UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    [butten setImage:image forState:UIControlStateNormal];
    butten.contentEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    [butten addTarget:target action:clic forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(35, 10, 12, 12)];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont systemFontOfSize:8];
    lable.backgroundColor = [UIColor greenColor];
    lable.layer.masksToBounds = YES;
    lable.layer.cornerRadius = 6;
    [butten addSubview:lable];

    if (count||count>0) {
        lable.hidden = NO;
        lable.text = [NSString stringWithFormat:@"%ld",(long)count];

            }else
            {
                lable.hidden = YES;
            }
}

-(void)addtarget:(id)target witiTItle:(NSString *)title with:(SEL)sel
{
    UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    [butten setTitle:title forState:UIControlStateNormal];
    [butten addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    [butten setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
}
-(void)addtarget:(id)target witishopTItle:(NSString *)title with:(SEL)sel
{

    TitleBtn *butten = [[TitleBtn alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
//    butten.selected = NO;
    [butten setTitle:title forState:UIControlStateNormal];
    [butten setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [butten setImage:[UIImage imageNamed:@"arrow_down.png"] forState:UIControlStateNormal];
    butten.titleLabel.font = [UIFont systemFontOfSize:14];
    [butten addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];

}


-(void)popVc
{
    UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [butten setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    butten.contentEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
    [butten addTarget:self action:@selector(popvcto) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
}
-(void)dissmissVc
{
    UIButton *butten = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [butten setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    butten.contentEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
    [butten addTarget:self action:@selector(dissVc) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
}

-(void)popwithTitle:(NSString *)title
{
    specialButten *butten = [[specialButten alloc]initWithFrame:CGRectMake(0, 0, 70, 30)];
    [butten setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    butten.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    [butten setTitle:title forState:UIControlStateNormal];
    butten.titleLabel.font = [UIFont systemFontOfSize:15];
    [butten addTarget:self action:@selector(popvcto) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butten];
}

-(void)popvcto
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)dissVc
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)addtarget:(id)target withTitile:(NSString *)title sel:(SEL)sel orignPointY:(CGFloat)pointY toVC:(UIViewController *)vc
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10*Kscr, pointY, 355*Kscr, 44*Kscr);
    button.backgroundColor = knavcolor;
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 5;
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    
    [vc.view addSubview:button];
}

@end
